{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 股票成交量变化预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "import torch\n",
    "import torch.nn\n",
    "import torch.optim"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据读取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>ExDividend</th>\n",
       "      <th>SplitRatio</th>\n",
       "      <th>AdjOpen</th>\n",
       "      <th>AdjHigh</th>\n",
       "      <th>AdjLow</th>\n",
       "      <th>AdjClose</th>\n",
       "      <th>AdjVolume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-03-27</th>\n",
       "      <td>156.310</td>\n",
       "      <td>162.8500</td>\n",
       "      <td>150.7500</td>\n",
       "      <td>152.1900</td>\n",
       "      <td>76787884.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>156.310</td>\n",
       "      <td>162.8500</td>\n",
       "      <td>150.7500</td>\n",
       "      <td>152.1900</td>\n",
       "      <td>76787884.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-26</th>\n",
       "      <td>160.820</td>\n",
       "      <td>161.1000</td>\n",
       "      <td>149.0200</td>\n",
       "      <td>160.0600</td>\n",
       "      <td>125438294.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>160.820</td>\n",
       "      <td>161.1000</td>\n",
       "      <td>149.0200</td>\n",
       "      <td>160.0600</td>\n",
       "      <td>125438294.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-23</th>\n",
       "      <td>165.440</td>\n",
       "      <td>167.1000</td>\n",
       "      <td>159.0200</td>\n",
       "      <td>159.3900</td>\n",
       "      <td>52306891.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>165.440</td>\n",
       "      <td>167.1000</td>\n",
       "      <td>159.0200</td>\n",
       "      <td>159.3900</td>\n",
       "      <td>52306891.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-22</th>\n",
       "      <td>166.130</td>\n",
       "      <td>170.2700</td>\n",
       "      <td>163.7200</td>\n",
       "      <td>164.8900</td>\n",
       "      <td>73389988.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>166.130</td>\n",
       "      <td>170.2700</td>\n",
       "      <td>163.7200</td>\n",
       "      <td>164.8900</td>\n",
       "      <td>73389988.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-21</th>\n",
       "      <td>164.800</td>\n",
       "      <td>173.4000</td>\n",
       "      <td>163.3000</td>\n",
       "      <td>169.3900</td>\n",
       "      <td>105350867.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>164.800</td>\n",
       "      <td>173.4000</td>\n",
       "      <td>163.3000</td>\n",
       "      <td>169.3900</td>\n",
       "      <td>105350867.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-20</th>\n",
       "      <td>167.470</td>\n",
       "      <td>170.2000</td>\n",
       "      <td>161.9500</td>\n",
       "      <td>168.1500</td>\n",
       "      <td>128925534.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>167.470</td>\n",
       "      <td>170.2000</td>\n",
       "      <td>161.9500</td>\n",
       "      <td>168.1500</td>\n",
       "      <td>128925534.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-19</th>\n",
       "      <td>177.010</td>\n",
       "      <td>177.1700</td>\n",
       "      <td>170.0600</td>\n",
       "      <td>172.5600</td>\n",
       "      <td>86897749.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>177.010</td>\n",
       "      <td>177.1700</td>\n",
       "      <td>170.0600</td>\n",
       "      <td>172.5600</td>\n",
       "      <td>86897749.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-16</th>\n",
       "      <td>184.490</td>\n",
       "      <td>185.3300</td>\n",
       "      <td>183.4100</td>\n",
       "      <td>185.0900</td>\n",
       "      <td>23090480.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>184.490</td>\n",
       "      <td>185.3300</td>\n",
       "      <td>183.4100</td>\n",
       "      <td>185.0900</td>\n",
       "      <td>23090480.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-15</th>\n",
       "      <td>183.240</td>\n",
       "      <td>184.0000</td>\n",
       "      <td>182.1900</td>\n",
       "      <td>183.8600</td>\n",
       "      <td>15461869.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>183.240</td>\n",
       "      <td>184.0000</td>\n",
       "      <td>182.1900</td>\n",
       "      <td>183.8600</td>\n",
       "      <td>15461869.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-14</th>\n",
       "      <td>182.600</td>\n",
       "      <td>184.2500</td>\n",
       "      <td>181.8500</td>\n",
       "      <td>184.1900</td>\n",
       "      <td>16426843.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>182.600</td>\n",
       "      <td>184.2500</td>\n",
       "      <td>181.8500</td>\n",
       "      <td>184.1900</td>\n",
       "      <td>16426843.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-13</th>\n",
       "      <td>185.610</td>\n",
       "      <td>185.9900</td>\n",
       "      <td>181.1100</td>\n",
       "      <td>181.8800</td>\n",
       "      <td>17742312.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>185.610</td>\n",
       "      <td>185.9900</td>\n",
       "      <td>181.1100</td>\n",
       "      <td>181.8800</td>\n",
       "      <td>17742312.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-12</th>\n",
       "      <td>185.230</td>\n",
       "      <td>186.1000</td>\n",
       "      <td>184.2200</td>\n",
       "      <td>184.7600</td>\n",
       "      <td>14873538.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>185.230</td>\n",
       "      <td>186.1000</td>\n",
       "      <td>184.2200</td>\n",
       "      <td>184.7600</td>\n",
       "      <td>14873538.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-09</th>\n",
       "      <td>183.910</td>\n",
       "      <td>185.5100</td>\n",
       "      <td>183.2100</td>\n",
       "      <td>185.2300</td>\n",
       "      <td>17952177.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>183.910</td>\n",
       "      <td>185.5100</td>\n",
       "      <td>183.2100</td>\n",
       "      <td>185.2300</td>\n",
       "      <td>17952177.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-08</th>\n",
       "      <td>183.560</td>\n",
       "      <td>184.4000</td>\n",
       "      <td>181.4500</td>\n",
       "      <td>182.3400</td>\n",
       "      <td>15336555.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>183.560</td>\n",
       "      <td>184.4000</td>\n",
       "      <td>181.4500</td>\n",
       "      <td>182.3400</td>\n",
       "      <td>15336555.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-07</th>\n",
       "      <td>178.740</td>\n",
       "      <td>183.8200</td>\n",
       "      <td>178.0700</td>\n",
       "      <td>183.7100</td>\n",
       "      <td>19097293.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>178.740</td>\n",
       "      <td>183.8200</td>\n",
       "      <td>178.0700</td>\n",
       "      <td>183.7100</td>\n",
       "      <td>19097293.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-06</th>\n",
       "      <td>181.780</td>\n",
       "      <td>182.3800</td>\n",
       "      <td>179.1100</td>\n",
       "      <td>179.7800</td>\n",
       "      <td>15086784.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>181.780</td>\n",
       "      <td>182.3800</td>\n",
       "      <td>179.1100</td>\n",
       "      <td>179.7800</td>\n",
       "      <td>15086784.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-05</th>\n",
       "      <td>176.200</td>\n",
       "      <td>181.1475</td>\n",
       "      <td>175.8900</td>\n",
       "      <td>180.4000</td>\n",
       "      <td>16189280.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>176.200</td>\n",
       "      <td>181.1475</td>\n",
       "      <td>175.8900</td>\n",
       "      <td>180.4000</td>\n",
       "      <td>16189280.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-02</th>\n",
       "      <td>173.290</td>\n",
       "      <td>177.1100</td>\n",
       "      <td>172.9900</td>\n",
       "      <td>176.6200</td>\n",
       "      <td>20025905.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>173.290</td>\n",
       "      <td>177.1100</td>\n",
       "      <td>172.9900</td>\n",
       "      <td>176.6200</td>\n",
       "      <td>20025905.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-01</th>\n",
       "      <td>179.010</td>\n",
       "      <td>180.1200</td>\n",
       "      <td>174.4100</td>\n",
       "      <td>175.9400</td>\n",
       "      <td>23201626.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>179.010</td>\n",
       "      <td>180.1200</td>\n",
       "      <td>174.4100</td>\n",
       "      <td>175.9400</td>\n",
       "      <td>23201626.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-28</th>\n",
       "      <td>182.300</td>\n",
       "      <td>182.8800</td>\n",
       "      <td>178.1400</td>\n",
       "      <td>178.3200</td>\n",
       "      <td>18208084.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>182.300</td>\n",
       "      <td>182.8800</td>\n",
       "      <td>178.1400</td>\n",
       "      <td>178.3200</td>\n",
       "      <td>18208084.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-27</th>\n",
       "      <td>184.450</td>\n",
       "      <td>184.7000</td>\n",
       "      <td>181.4600</td>\n",
       "      <td>181.4600</td>\n",
       "      <td>15649326.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>184.450</td>\n",
       "      <td>184.7000</td>\n",
       "      <td>181.4600</td>\n",
       "      <td>181.4600</td>\n",
       "      <td>15649326.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-26</th>\n",
       "      <td>184.580</td>\n",
       "      <td>185.6600</td>\n",
       "      <td>183.2228</td>\n",
       "      <td>184.9300</td>\n",
       "      <td>17418814.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>184.580</td>\n",
       "      <td>185.6600</td>\n",
       "      <td>183.2228</td>\n",
       "      <td>184.9300</td>\n",
       "      <td>17418814.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-23</th>\n",
       "      <td>179.900</td>\n",
       "      <td>183.3900</td>\n",
       "      <td>179.5100</td>\n",
       "      <td>183.2900</td>\n",
       "      <td>18621950.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>179.900</td>\n",
       "      <td>183.3900</td>\n",
       "      <td>179.5100</td>\n",
       "      <td>183.2900</td>\n",
       "      <td>18621950.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-22</th>\n",
       "      <td>178.700</td>\n",
       "      <td>180.2100</td>\n",
       "      <td>177.4100</td>\n",
       "      <td>178.9900</td>\n",
       "      <td>17085490.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>178.700</td>\n",
       "      <td>180.2100</td>\n",
       "      <td>177.4100</td>\n",
       "      <td>178.9900</td>\n",
       "      <td>17085490.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-21</th>\n",
       "      <td>176.710</td>\n",
       "      <td>181.2700</td>\n",
       "      <td>176.4000</td>\n",
       "      <td>177.9100</td>\n",
       "      <td>22844006.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>176.710</td>\n",
       "      <td>181.2700</td>\n",
       "      <td>176.4000</td>\n",
       "      <td>177.9100</td>\n",
       "      <td>22844006.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-20</th>\n",
       "      <td>175.770</td>\n",
       "      <td>177.9500</td>\n",
       "      <td>175.1100</td>\n",
       "      <td>176.0100</td>\n",
       "      <td>20887317.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>175.770</td>\n",
       "      <td>177.9500</td>\n",
       "      <td>175.1100</td>\n",
       "      <td>176.0100</td>\n",
       "      <td>20887317.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-16</th>\n",
       "      <td>178.990</td>\n",
       "      <td>179.8800</td>\n",
       "      <td>176.3000</td>\n",
       "      <td>177.3600</td>\n",
       "      <td>20475445.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>178.990</td>\n",
       "      <td>179.8800</td>\n",
       "      <td>176.3000</td>\n",
       "      <td>177.3600</td>\n",
       "      <td>20475445.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-15</th>\n",
       "      <td>180.500</td>\n",
       "      <td>180.5000</td>\n",
       "      <td>176.8400</td>\n",
       "      <td>179.9600</td>\n",
       "      <td>20554092.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>180.500</td>\n",
       "      <td>180.5000</td>\n",
       "      <td>176.8400</td>\n",
       "      <td>179.9600</td>\n",
       "      <td>20554092.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-14</th>\n",
       "      <td>173.450</td>\n",
       "      <td>179.8100</td>\n",
       "      <td>173.2119</td>\n",
       "      <td>179.5200</td>\n",
       "      <td>27963758.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>173.450</td>\n",
       "      <td>179.8100</td>\n",
       "      <td>173.2119</td>\n",
       "      <td>179.5200</td>\n",
       "      <td>27963758.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-13</th>\n",
       "      <td>175.620</td>\n",
       "      <td>175.9700</td>\n",
       "      <td>173.1000</td>\n",
       "      <td>173.1500</td>\n",
       "      <td>20880702.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>175.620</td>\n",
       "      <td>175.9700</td>\n",
       "      <td>173.1000</td>\n",
       "      <td>173.1500</td>\n",
       "      <td>20880702.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-29</th>\n",
       "      <td>31.920</td>\n",
       "      <td>31.9900</td>\n",
       "      <td>30.7600</td>\n",
       "      <td>31.0950</td>\n",
       "      <td>19526900.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>31.920</td>\n",
       "      <td>31.9900</td>\n",
       "      <td>30.7600</td>\n",
       "      <td>31.0950</td>\n",
       "      <td>19526900.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-28</th>\n",
       "      <td>31.960</td>\n",
       "      <td>32.1900</td>\n",
       "      <td>30.9000</td>\n",
       "      <td>31.3600</td>\n",
       "      <td>17713300.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>31.960</td>\n",
       "      <td>32.1900</td>\n",
       "      <td>30.9000</td>\n",
       "      <td>31.3600</td>\n",
       "      <td>17713300.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-27</th>\n",
       "      <td>32.460</td>\n",
       "      <td>32.9000</td>\n",
       "      <td>31.9000</td>\n",
       "      <td>32.2300</td>\n",
       "      <td>28568000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>32.460</td>\n",
       "      <td>32.9000</td>\n",
       "      <td>31.9000</td>\n",
       "      <td>32.2300</td>\n",
       "      <td>28568000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-26</th>\n",
       "      <td>32.690</td>\n",
       "      <td>33.4400</td>\n",
       "      <td>32.5000</td>\n",
       "      <td>33.1000</td>\n",
       "      <td>24858700.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>32.690</td>\n",
       "      <td>33.4400</td>\n",
       "      <td>32.5000</td>\n",
       "      <td>33.1000</td>\n",
       "      <td>24858700.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-25</th>\n",
       "      <td>32.860</td>\n",
       "      <td>33.0200</td>\n",
       "      <td>31.5500</td>\n",
       "      <td>32.0600</td>\n",
       "      <td>24352900.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>32.860</td>\n",
       "      <td>33.0200</td>\n",
       "      <td>31.5500</td>\n",
       "      <td>32.0600</td>\n",
       "      <td>24352900.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-22</th>\n",
       "      <td>32.410</td>\n",
       "      <td>33.4500</td>\n",
       "      <td>32.0600</td>\n",
       "      <td>33.0500</td>\n",
       "      <td>74834000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>32.410</td>\n",
       "      <td>33.4500</td>\n",
       "      <td>32.0600</td>\n",
       "      <td>33.0500</td>\n",
       "      <td>74834000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-21</th>\n",
       "      <td>31.670</td>\n",
       "      <td>32.5000</td>\n",
       "      <td>31.5100</td>\n",
       "      <td>31.8400</td>\n",
       "      <td>21875300.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>31.670</td>\n",
       "      <td>32.5000</td>\n",
       "      <td>31.5100</td>\n",
       "      <td>31.8400</td>\n",
       "      <td>21875300.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-20</th>\n",
       "      <td>31.920</td>\n",
       "      <td>31.9288</td>\n",
       "      <td>31.1500</td>\n",
       "      <td>31.6000</td>\n",
       "      <td>15553600.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>31.920</td>\n",
       "      <td>31.9288</td>\n",
       "      <td>31.1500</td>\n",
       "      <td>31.6000</td>\n",
       "      <td>15553600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-19</th>\n",
       "      <td>31.535</td>\n",
       "      <td>32.1800</td>\n",
       "      <td>30.7000</td>\n",
       "      <td>31.9110</td>\n",
       "      <td>30849000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>31.535</td>\n",
       "      <td>32.1800</td>\n",
       "      <td>30.7000</td>\n",
       "      <td>31.9110</td>\n",
       "      <td>30849000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-18</th>\n",
       "      <td>29.955</td>\n",
       "      <td>32.0800</td>\n",
       "      <td>29.4100</td>\n",
       "      <td>31.4100</td>\n",
       "      <td>42978900.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>29.955</td>\n",
       "      <td>32.0800</td>\n",
       "      <td>29.4100</td>\n",
       "      <td>31.4100</td>\n",
       "      <td>42978900.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-15</th>\n",
       "      <td>28.505</td>\n",
       "      <td>30.1000</td>\n",
       "      <td>28.3500</td>\n",
       "      <td>30.0140</td>\n",
       "      <td>43563800.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>28.505</td>\n",
       "      <td>30.1000</td>\n",
       "      <td>28.3500</td>\n",
       "      <td>30.0140</td>\n",
       "      <td>43563800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-14</th>\n",
       "      <td>27.650</td>\n",
       "      <td>28.3200</td>\n",
       "      <td>27.3800</td>\n",
       "      <td>28.2900</td>\n",
       "      <td>16855000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>27.650</td>\n",
       "      <td>28.3200</td>\n",
       "      <td>27.3800</td>\n",
       "      <td>28.2900</td>\n",
       "      <td>16855000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-13</th>\n",
       "      <td>27.660</td>\n",
       "      <td>28.1000</td>\n",
       "      <td>27.1000</td>\n",
       "      <td>27.2700</td>\n",
       "      <td>17102800.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>27.660</td>\n",
       "      <td>28.1000</td>\n",
       "      <td>27.1000</td>\n",
       "      <td>27.2700</td>\n",
       "      <td>17102800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-12</th>\n",
       "      <td>27.480</td>\n",
       "      <td>27.7700</td>\n",
       "      <td>26.9600</td>\n",
       "      <td>27.4000</td>\n",
       "      <td>15816800.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>27.480</td>\n",
       "      <td>27.7700</td>\n",
       "      <td>26.9600</td>\n",
       "      <td>27.4000</td>\n",
       "      <td>15816800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-11</th>\n",
       "      <td>27.180</td>\n",
       "      <td>28.0700</td>\n",
       "      <td>26.8350</td>\n",
       "      <td>27.0050</td>\n",
       "      <td>28219600.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>27.180</td>\n",
       "      <td>28.0700</td>\n",
       "      <td>26.8350</td>\n",
       "      <td>27.0050</td>\n",
       "      <td>28219600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-08</th>\n",
       "      <td>26.550</td>\n",
       "      <td>27.7600</td>\n",
       "      <td>26.4400</td>\n",
       "      <td>27.1000</td>\n",
       "      <td>38034000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>26.550</td>\n",
       "      <td>27.7600</td>\n",
       "      <td>26.4400</td>\n",
       "      <td>27.1000</td>\n",
       "      <td>38034000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-07</th>\n",
       "      <td>27.000</td>\n",
       "      <td>27.3500</td>\n",
       "      <td>26.1500</td>\n",
       "      <td>26.3100</td>\n",
       "      <td>26159500.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>27.000</td>\n",
       "      <td>27.3500</td>\n",
       "      <td>26.1500</td>\n",
       "      <td>26.3100</td>\n",
       "      <td>26159500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-06</th>\n",
       "      <td>26.070</td>\n",
       "      <td>27.1700</td>\n",
       "      <td>25.5200</td>\n",
       "      <td>26.8100</td>\n",
       "      <td>61489200.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>26.070</td>\n",
       "      <td>27.1700</td>\n",
       "      <td>25.5200</td>\n",
       "      <td>26.8100</td>\n",
       "      <td>61489200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-05</th>\n",
       "      <td>26.700</td>\n",
       "      <td>27.7600</td>\n",
       "      <td>25.7500</td>\n",
       "      <td>25.8690</td>\n",
       "      <td>42473400.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>26.700</td>\n",
       "      <td>27.7600</td>\n",
       "      <td>25.7500</td>\n",
       "      <td>25.8690</td>\n",
       "      <td>42473400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-04</th>\n",
       "      <td>27.200</td>\n",
       "      <td>27.6500</td>\n",
       "      <td>26.4400</td>\n",
       "      <td>26.9000</td>\n",
       "      <td>35230300.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>27.200</td>\n",
       "      <td>27.6500</td>\n",
       "      <td>26.4400</td>\n",
       "      <td>26.9000</td>\n",
       "      <td>35230300.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-06-01</th>\n",
       "      <td>28.892</td>\n",
       "      <td>29.1500</td>\n",
       "      <td>27.3900</td>\n",
       "      <td>27.7200</td>\n",
       "      <td>41855500.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>28.892</td>\n",
       "      <td>29.1500</td>\n",
       "      <td>27.3900</td>\n",
       "      <td>27.7200</td>\n",
       "      <td>41855500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-05-31</th>\n",
       "      <td>28.545</td>\n",
       "      <td>29.6700</td>\n",
       "      <td>26.8300</td>\n",
       "      <td>29.6000</td>\n",
       "      <td>111639200.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>28.545</td>\n",
       "      <td>29.6700</td>\n",
       "      <td>26.8300</td>\n",
       "      <td>29.6000</td>\n",
       "      <td>111639200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-05-30</th>\n",
       "      <td>28.695</td>\n",
       "      <td>29.5500</td>\n",
       "      <td>27.8600</td>\n",
       "      <td>28.1900</td>\n",
       "      <td>57267900.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>28.695</td>\n",
       "      <td>29.5500</td>\n",
       "      <td>27.8600</td>\n",
       "      <td>28.1900</td>\n",
       "      <td>57267900.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-05-29</th>\n",
       "      <td>31.480</td>\n",
       "      <td>31.6900</td>\n",
       "      <td>28.6500</td>\n",
       "      <td>28.8400</td>\n",
       "      <td>78063400.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>31.480</td>\n",
       "      <td>31.6900</td>\n",
       "      <td>28.6500</td>\n",
       "      <td>28.8400</td>\n",
       "      <td>78063400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-05-25</th>\n",
       "      <td>32.900</td>\n",
       "      <td>32.9500</td>\n",
       "      <td>31.1100</td>\n",
       "      <td>31.9100</td>\n",
       "      <td>37149800.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>32.900</td>\n",
       "      <td>32.9500</td>\n",
       "      <td>31.1100</td>\n",
       "      <td>31.9100</td>\n",
       "      <td>37149800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-05-24</th>\n",
       "      <td>32.950</td>\n",
       "      <td>33.2100</td>\n",
       "      <td>31.7700</td>\n",
       "      <td>33.0300</td>\n",
       "      <td>50237200.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>32.950</td>\n",
       "      <td>33.2100</td>\n",
       "      <td>31.7700</td>\n",
       "      <td>33.0300</td>\n",
       "      <td>50237200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-05-23</th>\n",
       "      <td>31.370</td>\n",
       "      <td>32.5000</td>\n",
       "      <td>31.3600</td>\n",
       "      <td>32.0000</td>\n",
       "      <td>73600000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>31.370</td>\n",
       "      <td>32.5000</td>\n",
       "      <td>31.3600</td>\n",
       "      <td>32.0000</td>\n",
       "      <td>73600000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-05-22</th>\n",
       "      <td>32.610</td>\n",
       "      <td>33.5900</td>\n",
       "      <td>30.9400</td>\n",
       "      <td>31.0000</td>\n",
       "      <td>101786600.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>32.610</td>\n",
       "      <td>33.5900</td>\n",
       "      <td>30.9400</td>\n",
       "      <td>31.0000</td>\n",
       "      <td>101786600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-05-21</th>\n",
       "      <td>36.530</td>\n",
       "      <td>36.6600</td>\n",
       "      <td>33.0000</td>\n",
       "      <td>34.0300</td>\n",
       "      <td>168192700.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>36.530</td>\n",
       "      <td>36.6600</td>\n",
       "      <td>33.0000</td>\n",
       "      <td>34.0300</td>\n",
       "      <td>168192700.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-05-18</th>\n",
       "      <td>42.050</td>\n",
       "      <td>45.0000</td>\n",
       "      <td>38.0000</td>\n",
       "      <td>38.2318</td>\n",
       "      <td>573576400.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>42.050</td>\n",
       "      <td>45.0000</td>\n",
       "      <td>38.0000</td>\n",
       "      <td>38.2318</td>\n",
       "      <td>573576400.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1472 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               Open      High       Low     Close       Volume  ExDividend  \\\n",
       "Date                                                                         \n",
       "2018-03-27  156.310  162.8500  150.7500  152.1900   76787884.0         0.0   \n",
       "2018-03-26  160.820  161.1000  149.0200  160.0600  125438294.0         0.0   \n",
       "2018-03-23  165.440  167.1000  159.0200  159.3900   52306891.0         0.0   \n",
       "2018-03-22  166.130  170.2700  163.7200  164.8900   73389988.0         0.0   \n",
       "2018-03-21  164.800  173.4000  163.3000  169.3900  105350867.0         0.0   \n",
       "2018-03-20  167.470  170.2000  161.9500  168.1500  128925534.0         0.0   \n",
       "2018-03-19  177.010  177.1700  170.0600  172.5600   86897749.0         0.0   \n",
       "2018-03-16  184.490  185.3300  183.4100  185.0900   23090480.0         0.0   \n",
       "2018-03-15  183.240  184.0000  182.1900  183.8600   15461869.0         0.0   \n",
       "2018-03-14  182.600  184.2500  181.8500  184.1900   16426843.0         0.0   \n",
       "2018-03-13  185.610  185.9900  181.1100  181.8800   17742312.0         0.0   \n",
       "2018-03-12  185.230  186.1000  184.2200  184.7600   14873538.0         0.0   \n",
       "2018-03-09  183.910  185.5100  183.2100  185.2300   17952177.0         0.0   \n",
       "2018-03-08  183.560  184.4000  181.4500  182.3400   15336555.0         0.0   \n",
       "2018-03-07  178.740  183.8200  178.0700  183.7100   19097293.0         0.0   \n",
       "2018-03-06  181.780  182.3800  179.1100  179.7800   15086784.0         0.0   \n",
       "2018-03-05  176.200  181.1475  175.8900  180.4000   16189280.0         0.0   \n",
       "2018-03-02  173.290  177.1100  172.9900  176.6200   20025905.0         0.0   \n",
       "2018-03-01  179.010  180.1200  174.4100  175.9400   23201626.0         0.0   \n",
       "2018-02-28  182.300  182.8800  178.1400  178.3200   18208084.0         0.0   \n",
       "2018-02-27  184.450  184.7000  181.4600  181.4600   15649326.0         0.0   \n",
       "2018-02-26  184.580  185.6600  183.2228  184.9300   17418814.0         0.0   \n",
       "2018-02-23  179.900  183.3900  179.5100  183.2900   18621950.0         0.0   \n",
       "2018-02-22  178.700  180.2100  177.4100  178.9900   17085490.0         0.0   \n",
       "2018-02-21  176.710  181.2700  176.4000  177.9100   22844006.0         0.0   \n",
       "2018-02-20  175.770  177.9500  175.1100  176.0100   20887317.0         0.0   \n",
       "2018-02-16  178.990  179.8800  176.3000  177.3600   20475445.0         0.0   \n",
       "2018-02-15  180.500  180.5000  176.8400  179.9600   20554092.0         0.0   \n",
       "2018-02-14  173.450  179.8100  173.2119  179.5200   27963758.0         0.0   \n",
       "2018-02-13  175.620  175.9700  173.1000  173.1500   20880702.0         0.0   \n",
       "...             ...       ...       ...       ...          ...         ...   \n",
       "2012-06-29   31.920   31.9900   30.7600   31.0950   19526900.0         0.0   \n",
       "2012-06-28   31.960   32.1900   30.9000   31.3600   17713300.0         0.0   \n",
       "2012-06-27   32.460   32.9000   31.9000   32.2300   28568000.0         0.0   \n",
       "2012-06-26   32.690   33.4400   32.5000   33.1000   24858700.0         0.0   \n",
       "2012-06-25   32.860   33.0200   31.5500   32.0600   24352900.0         0.0   \n",
       "2012-06-22   32.410   33.4500   32.0600   33.0500   74834000.0         0.0   \n",
       "2012-06-21   31.670   32.5000   31.5100   31.8400   21875300.0         0.0   \n",
       "2012-06-20   31.920   31.9288   31.1500   31.6000   15553600.0         0.0   \n",
       "2012-06-19   31.535   32.1800   30.7000   31.9110   30849000.0         0.0   \n",
       "2012-06-18   29.955   32.0800   29.4100   31.4100   42978900.0         0.0   \n",
       "2012-06-15   28.505   30.1000   28.3500   30.0140   43563800.0         0.0   \n",
       "2012-06-14   27.650   28.3200   27.3800   28.2900   16855000.0         0.0   \n",
       "2012-06-13   27.660   28.1000   27.1000   27.2700   17102800.0         0.0   \n",
       "2012-06-12   27.480   27.7700   26.9600   27.4000   15816800.0         0.0   \n",
       "2012-06-11   27.180   28.0700   26.8350   27.0050   28219600.0         0.0   \n",
       "2012-06-08   26.550   27.7600   26.4400   27.1000   38034000.0         0.0   \n",
       "2012-06-07   27.000   27.3500   26.1500   26.3100   26159500.0         0.0   \n",
       "2012-06-06   26.070   27.1700   25.5200   26.8100   61489200.0         0.0   \n",
       "2012-06-05   26.700   27.7600   25.7500   25.8690   42473400.0         0.0   \n",
       "2012-06-04   27.200   27.6500   26.4400   26.9000   35230300.0         0.0   \n",
       "2012-06-01   28.892   29.1500   27.3900   27.7200   41855500.0         0.0   \n",
       "2012-05-31   28.545   29.6700   26.8300   29.6000  111639200.0         0.0   \n",
       "2012-05-30   28.695   29.5500   27.8600   28.1900   57267900.0         0.0   \n",
       "2012-05-29   31.480   31.6900   28.6500   28.8400   78063400.0         0.0   \n",
       "2012-05-25   32.900   32.9500   31.1100   31.9100   37149800.0         0.0   \n",
       "2012-05-24   32.950   33.2100   31.7700   33.0300   50237200.0         0.0   \n",
       "2012-05-23   31.370   32.5000   31.3600   32.0000   73600000.0         0.0   \n",
       "2012-05-22   32.610   33.5900   30.9400   31.0000  101786600.0         0.0   \n",
       "2012-05-21   36.530   36.6600   33.0000   34.0300  168192700.0         0.0   \n",
       "2012-05-18   42.050   45.0000   38.0000   38.2318  573576400.0         0.0   \n",
       "\n",
       "            SplitRatio  AdjOpen   AdjHigh    AdjLow  AdjClose    AdjVolume  \n",
       "Date                                                                        \n",
       "2018-03-27         1.0  156.310  162.8500  150.7500  152.1900   76787884.0  \n",
       "2018-03-26         1.0  160.820  161.1000  149.0200  160.0600  125438294.0  \n",
       "2018-03-23         1.0  165.440  167.1000  159.0200  159.3900   52306891.0  \n",
       "2018-03-22         1.0  166.130  170.2700  163.7200  164.8900   73389988.0  \n",
       "2018-03-21         1.0  164.800  173.4000  163.3000  169.3900  105350867.0  \n",
       "2018-03-20         1.0  167.470  170.2000  161.9500  168.1500  128925534.0  \n",
       "2018-03-19         1.0  177.010  177.1700  170.0600  172.5600   86897749.0  \n",
       "2018-03-16         1.0  184.490  185.3300  183.4100  185.0900   23090480.0  \n",
       "2018-03-15         1.0  183.240  184.0000  182.1900  183.8600   15461869.0  \n",
       "2018-03-14         1.0  182.600  184.2500  181.8500  184.1900   16426843.0  \n",
       "2018-03-13         1.0  185.610  185.9900  181.1100  181.8800   17742312.0  \n",
       "2018-03-12         1.0  185.230  186.1000  184.2200  184.7600   14873538.0  \n",
       "2018-03-09         1.0  183.910  185.5100  183.2100  185.2300   17952177.0  \n",
       "2018-03-08         1.0  183.560  184.4000  181.4500  182.3400   15336555.0  \n",
       "2018-03-07         1.0  178.740  183.8200  178.0700  183.7100   19097293.0  \n",
       "2018-03-06         1.0  181.780  182.3800  179.1100  179.7800   15086784.0  \n",
       "2018-03-05         1.0  176.200  181.1475  175.8900  180.4000   16189280.0  \n",
       "2018-03-02         1.0  173.290  177.1100  172.9900  176.6200   20025905.0  \n",
       "2018-03-01         1.0  179.010  180.1200  174.4100  175.9400   23201626.0  \n",
       "2018-02-28         1.0  182.300  182.8800  178.1400  178.3200   18208084.0  \n",
       "2018-02-27         1.0  184.450  184.7000  181.4600  181.4600   15649326.0  \n",
       "2018-02-26         1.0  184.580  185.6600  183.2228  184.9300   17418814.0  \n",
       "2018-02-23         1.0  179.900  183.3900  179.5100  183.2900   18621950.0  \n",
       "2018-02-22         1.0  178.700  180.2100  177.4100  178.9900   17085490.0  \n",
       "2018-02-21         1.0  176.710  181.2700  176.4000  177.9100   22844006.0  \n",
       "2018-02-20         1.0  175.770  177.9500  175.1100  176.0100   20887317.0  \n",
       "2018-02-16         1.0  178.990  179.8800  176.3000  177.3600   20475445.0  \n",
       "2018-02-15         1.0  180.500  180.5000  176.8400  179.9600   20554092.0  \n",
       "2018-02-14         1.0  173.450  179.8100  173.2119  179.5200   27963758.0  \n",
       "2018-02-13         1.0  175.620  175.9700  173.1000  173.1500   20880702.0  \n",
       "...                ...      ...       ...       ...       ...          ...  \n",
       "2012-06-29         1.0   31.920   31.9900   30.7600   31.0950   19526900.0  \n",
       "2012-06-28         1.0   31.960   32.1900   30.9000   31.3600   17713300.0  \n",
       "2012-06-27         1.0   32.460   32.9000   31.9000   32.2300   28568000.0  \n",
       "2012-06-26         1.0   32.690   33.4400   32.5000   33.1000   24858700.0  \n",
       "2012-06-25         1.0   32.860   33.0200   31.5500   32.0600   24352900.0  \n",
       "2012-06-22         1.0   32.410   33.4500   32.0600   33.0500   74834000.0  \n",
       "2012-06-21         1.0   31.670   32.5000   31.5100   31.8400   21875300.0  \n",
       "2012-06-20         1.0   31.920   31.9288   31.1500   31.6000   15553600.0  \n",
       "2012-06-19         1.0   31.535   32.1800   30.7000   31.9110   30849000.0  \n",
       "2012-06-18         1.0   29.955   32.0800   29.4100   31.4100   42978900.0  \n",
       "2012-06-15         1.0   28.505   30.1000   28.3500   30.0140   43563800.0  \n",
       "2012-06-14         1.0   27.650   28.3200   27.3800   28.2900   16855000.0  \n",
       "2012-06-13         1.0   27.660   28.1000   27.1000   27.2700   17102800.0  \n",
       "2012-06-12         1.0   27.480   27.7700   26.9600   27.4000   15816800.0  \n",
       "2012-06-11         1.0   27.180   28.0700   26.8350   27.0050   28219600.0  \n",
       "2012-06-08         1.0   26.550   27.7600   26.4400   27.1000   38034000.0  \n",
       "2012-06-07         1.0   27.000   27.3500   26.1500   26.3100   26159500.0  \n",
       "2012-06-06         1.0   26.070   27.1700   25.5200   26.8100   61489200.0  \n",
       "2012-06-05         1.0   26.700   27.7600   25.7500   25.8690   42473400.0  \n",
       "2012-06-04         1.0   27.200   27.6500   26.4400   26.9000   35230300.0  \n",
       "2012-06-01         1.0   28.892   29.1500   27.3900   27.7200   41855500.0  \n",
       "2012-05-31         1.0   28.545   29.6700   26.8300   29.6000  111639200.0  \n",
       "2012-05-30         1.0   28.695   29.5500   27.8600   28.1900   57267900.0  \n",
       "2012-05-29         1.0   31.480   31.6900   28.6500   28.8400   78063400.0  \n",
       "2012-05-25         1.0   32.900   32.9500   31.1100   31.9100   37149800.0  \n",
       "2012-05-24         1.0   32.950   33.2100   31.7700   33.0300   50237200.0  \n",
       "2012-05-23         1.0   31.370   32.5000   31.3600   32.0000   73600000.0  \n",
       "2012-05-22         1.0   32.610   33.5900   30.9400   31.0000  101786600.0  \n",
       "2012-05-21         1.0   36.530   36.6600   33.0000   34.0300  168192700.0  \n",
       "2012-05-18         1.0   42.050   45.0000   38.0000   38.2318  573576400.0  \n",
       "\n",
       "[1472 rows x 12 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url = 'http://raw.githubusercontent.com/zhiqingxiao/pytorch-book/master/chapter06_logistic/FB.csv'\n",
    "df = pd.read_csv(url, index_col=0)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(                Open      High       Low     Close     Volume\n",
       " Date                                                         \n",
       " 2018-03-27  2.526504  2.693290  2.395682  2.395569   1.267472\n",
       " 2018-03-26  2.671127  2.637488  2.339793  2.648029   2.944486\n",
       " 2018-03-23  2.819278  2.828808  2.662850  2.626536   0.423596\n",
       " 2018-03-22  2.841404  2.929889  2.814687  2.802970   1.150344\n",
       " 2018-03-21  2.798755  3.029695  2.801118  2.947325   2.252058\n",
       " 2018-03-20  2.884374  2.927657  2.757506  2.907547   3.064693\n",
       " 2018-03-19  3.190296  3.149908  3.019505  3.049015   1.615966\n",
       " 2018-03-16  3.430159  3.410103  3.450785  3.450963  -0.583514\n",
       " 2018-03-15  3.390075  3.367694  3.411372  3.411506  -0.846478\n",
       " 2018-03-14  3.369552  3.375666  3.400388  3.422092  -0.813214\n",
       " 2018-03-13  3.466075  3.431149  3.376482  3.347990  -0.767869\n",
       " 2018-03-12  3.453889  3.434656  3.476953  3.440377  -0.866758\n",
       " 2018-03-09  3.411560  3.415843  3.444324  3.455454  -0.760635\n",
       " 2018-03-08  3.400337  3.380449  3.387466  3.362746  -0.850797\n",
       " 2018-03-07  3.245772  3.361954  3.278273  3.406694  -0.721162\n",
       " 2018-03-06  3.343257  3.316037  3.311871  3.280624  -0.859407\n",
       " 2018-03-05  3.164322  3.276737  3.207847  3.300513  -0.821403\n",
       " 2018-03-02  3.071006  3.147994  3.114160  3.179255  -0.689152\n",
       " 2018-03-01  3.254431  3.243973  3.160034  3.157441  -0.579683\n",
       " 2018-02-28  3.359932  3.331981  3.280534  3.233789  -0.751814\n",
       " 2018-02-27  3.428877  3.390015  3.387789  3.334516  -0.840016\n",
       " 2018-02-26  3.433045  3.420626  3.444738  3.445830  -0.779021\n",
       " 2018-02-23  3.282971  3.348243  3.324793  3.393221  -0.737548\n",
       " 2018-02-22  3.244490  3.246843  3.256951  3.255282  -0.790510\n",
       " 2018-02-21  3.180676  3.280643  3.224323  3.220637  -0.592010\n",
       " 2018-02-20  3.150533  3.174779  3.182648  3.159687  -0.659459\n",
       " 2018-02-16  3.253789  3.236321  3.221092  3.202993  -0.673656\n",
       " 2018-02-15  3.302211  3.256090  3.238537  3.286398  -0.670945\n",
       " 2018-02-14  3.076137  3.234089  3.121329  3.272283  -0.415529\n",
       " 2018-02-13  3.145723  3.111643  3.117714  3.067941  -0.659687\n",
       " ...              ...       ...       ...       ...        ...\n",
       " 2012-06-29 -1.462345 -1.479408 -1.480676 -1.489020  -0.706353\n",
       " 2012-06-28 -1.461062 -1.473031 -1.476153 -1.480519  -0.768869\n",
       " 2012-06-27 -1.445028 -1.450391 -1.443847 -1.452610  -0.394700\n",
       " 2012-06-26 -1.437653 -1.433173 -1.424464 -1.424701  -0.522563\n",
       " 2012-06-25 -1.432201 -1.446565 -1.455154 -1.458063  -0.539998\n",
       " 2012-06-22 -1.446632 -1.432854 -1.438679 -1.426305   1.200121\n",
       " 2012-06-21 -1.470361 -1.463146 -1.456447 -1.465121  -0.625402\n",
       " 2012-06-20 -1.462345 -1.481360 -1.468077 -1.472820  -0.843316\n",
       " 2012-06-19 -1.474690 -1.473350 -1.482614 -1.462843  -0.316073\n",
       " 2012-06-18 -1.525357 -1.476539 -1.524289 -1.478915   0.102053\n",
       " 2012-06-15 -1.571854 -1.539674 -1.558533 -1.523697   0.122215\n",
       " 2012-06-14 -1.599272 -1.596433 -1.589869 -1.579001  -0.798456\n",
       " 2012-06-13 -1.598951 -1.603448 -1.598915 -1.611721  -0.789914\n",
       " 2012-06-12 -1.604723 -1.613970 -1.603437 -1.607551  -0.834243\n",
       " 2012-06-11 -1.614343 -1.604404 -1.607476 -1.620222  -0.406710\n",
       " 2012-06-08 -1.634546 -1.614289 -1.620236 -1.617175  -0.068401\n",
       " 2012-06-07 -1.620116 -1.627363 -1.629605 -1.642517  -0.477723\n",
       " 2012-06-06 -1.649938 -1.633102 -1.649958 -1.626477   0.740116\n",
       " 2012-06-05 -1.629736 -1.614289 -1.642527 -1.656664   0.084628\n",
       " 2012-06-04 -1.613702 -1.617797 -1.620236 -1.623590  -0.165046\n",
       " 2012-06-01 -1.559444 -1.569967 -1.589546 -1.597286   0.063329\n",
       " 2012-05-31 -1.570572 -1.553386 -1.607637 -1.536977   2.468821\n",
       " 2012-05-30 -1.565761 -1.557212 -1.574362 -1.582209   0.594605\n",
       " 2012-05-29 -1.476454 -1.488974 -1.548841 -1.561357   1.311440\n",
       " 2012-05-25 -1.430919 -1.448797 -1.469369 -1.462875  -0.098880\n",
       " 2012-05-24 -1.429315 -1.440507 -1.448047 -1.426947   0.352252\n",
       " 2012-05-23 -1.479982 -1.463146 -1.461293 -1.459988   1.157584\n",
       " 2012-05-22 -1.440218 -1.428390 -1.474861 -1.492067   2.129195\n",
       " 2012-05-21 -1.314514 -1.330497 -1.408311 -1.394868   4.418259\n",
       " 2012-05-18 -1.137503 -1.064562 -1.246783 -1.260079  18.392115\n",
       " \n",
       " [1472 rows x 5 columns], Date\n",
       " 2018-03-27    0\n",
       " 2018-03-26    0\n",
       " 2018-03-23    1\n",
       " 2018-03-22    0\n",
       " 2018-03-21    0\n",
       " 2018-03-20    0\n",
       " 2018-03-19    1\n",
       " 2018-03-16    1\n",
       " 2018-03-15    1\n",
       " 2018-03-14    0\n",
       " 2018-03-13    0\n",
       " 2018-03-12    1\n",
       " 2018-03-09    0\n",
       " 2018-03-08    1\n",
       " 2018-03-07    0\n",
       " 2018-03-06    1\n",
       " 2018-03-05    0\n",
       " 2018-03-02    0\n",
       " 2018-03-01    0\n",
       " 2018-02-28    1\n",
       " 2018-02-27    1\n",
       " 2018-02-26    0\n",
       " 2018-02-23    0\n",
       " 2018-02-22    1\n",
       " 2018-02-21    0\n",
       " 2018-02-20    1\n",
       " 2018-02-16    1\n",
       " 2018-02-15    0\n",
       " 2018-02-14    0\n",
       " 2018-02-13    1\n",
       "              ..\n",
       " 2012-06-29    0\n",
       " 2012-06-28    1\n",
       " 2012-06-27    0\n",
       " 2012-06-26    1\n",
       " 2012-06-25    1\n",
       " 2012-06-22    0\n",
       " 2012-06-21    1\n",
       " 2012-06-20    1\n",
       " 2012-06-19    0\n",
       " 2012-06-18    0\n",
       " 2012-06-15    0\n",
       " 2012-06-14    1\n",
       " 2012-06-13    0\n",
       " 2012-06-12    1\n",
       " 2012-06-11    0\n",
       " 2012-06-08    0\n",
       " 2012-06-07    1\n",
       " 2012-06-06    0\n",
       " 2012-06-05    1\n",
       " 2012-06-04    1\n",
       " 2012-06-01    0\n",
       " 2012-05-31    0\n",
       " 2012-05-30    1\n",
       " 2012-05-29    0\n",
       " 2012-05-25    1\n",
       " 2012-05-24    0\n",
       " 2012-05-23    0\n",
       " 2012-05-22    0\n",
       " 2012-05-21    0\n",
       " 2012-05-18    0\n",
       " Name: Volume, Length: 1472, dtype: int32)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_start, train_end = sum(df.index >= '2017'), sum(df.index >= '2013')\n",
    "test_start, test_end = sum(df.index >= '2018'), sum(df.index >= '2017')\n",
    "n_total_train = train_end - train_start\n",
    "n_total_test = test_end - test_start\n",
    "s_mean = df[train_start:train_end].mean()\n",
    "s_std = df[train_start:train_end].std()\n",
    "n_features = 5\n",
    "df_feature = ((df - s_mean) / s_std).iloc[:, :n_features]\n",
    "s_label = (df['Volume'] < df['Volume'].shift(1)).astype(int)\n",
    "df_feature, s_label"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "训练和测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#0, 损失 = 0.797557, \n",
      "训练集准确率 = 0.5059523809523809, 测试集准确率 = 0.456\n",
      "#500, 损失 = 0.660889, \n",
      "训练集准确率 = 0.623015873015873, 测试集准确率 = 0.564\n",
      "#1000, 损失 = 0.658926, \n",
      "训练集准确率 = 0.6091269841269841, 测试集准确率 = 0.548\n",
      "#1500, 损失 = 0.658904, \n",
      "训练集准确率 = 0.6101190476190477, 测试集准确率 = 0.548\n",
      "#2000, 损失 = 0.658884, \n",
      "训练集准确率 = 0.6101190476190477, 测试集准确率 = 0.548\n",
      "#2500, 损失 = 0.658859, \n",
      "训练集准确率 = 0.6091269841269841, 测试集准确率 = 0.548\n",
      "#3000, 损失 = 0.658825, \n",
      "训练集准确率 = 0.6091269841269841, 测试集准确率 = 0.548\n",
      "#3500, 损失 = 0.658782, \n",
      "训练集准确率 = 0.6081349206349206, 测试集准确率 = 0.548\n",
      "#4000, 损失 = 0.658726, \n",
      "训练集准确率 = 0.6081349206349206, 测试集准确率 = 0.548\n",
      "#4500, 损失 = 0.658655, \n",
      "训练集准确率 = 0.6101190476190477, 测试集准确率 = 0.548\n",
      "#5000, 损失 = 0.658565, \n",
      "训练集准确率 = 0.6101190476190477, 测试集准确率 = 0.548\n",
      "#5500, 损失 = 0.658451, \n",
      "训练集准确率 = 0.6101190476190477, 测试集准确率 = 0.548\n",
      "#6000, 损失 = 0.658308, \n",
      "训练集准确率 = 0.6101190476190477, 测试集准确率 = 0.548\n",
      "#6500, 损失 = 0.658131, \n",
      "训练集准确率 = 0.6111111111111112, 测试集准确率 = 0.548\n",
      "#7000, 损失 = 0.657913, \n",
      "训练集准确率 = 0.6121031746031746, 测试集准确率 = 0.548\n",
      "#7500, 损失 = 0.65765, \n",
      "训练集准确率 = 0.6130952380952381, 测试集准确率 = 0.548\n",
      "#8000, 损失 = 0.657338, \n",
      "训练集准确率 = 0.6101190476190477, 测试集准确率 = 0.544\n",
      "#8500, 损失 = 0.656979, \n",
      "训练集准确率 = 0.6121031746031746, 测试集准确率 = 0.556\n",
      "#9000, 损失 = 0.656578, \n",
      "训练集准确率 = 0.6160714285714286, 测试集准确率 = 0.556\n",
      "#9500, 损失 = 0.656143, \n",
      "训练集准确率 = 0.6150793650793651, 测试集准确率 = 0.548\n",
      "#10000, 损失 = 0.655688, \n",
      "训练集准确率 = 0.6160714285714286, 测试集准确率 = 0.556\n",
      "#10500, 损失 = 0.655226, \n",
      "训练集准确率 = 0.6180555555555556, 测试集准确率 = 0.572\n",
      "#11000, 损失 = 0.654769, \n",
      "训练集准确率 = 0.625, 测试集准确率 = 0.572\n",
      "#11500, 损失 = 0.654324, \n",
      "训练集准确率 = 0.6279761904761905, 测试集准确率 = 0.588\n",
      "#12000, 损失 = 0.6539, \n",
      "训练集准确率 = 0.6279761904761905, 测试集准确率 = 0.588\n",
      "#12500, 损失 = 0.653498, \n",
      "训练集准确率 = 0.6299603174603174, 测试集准确率 = 0.592\n",
      "#13000, 损失 = 0.653121, \n",
      "训练集准确率 = 0.6299603174603174, 测试集准确率 = 0.588\n",
      "#13500, 损失 = 0.652768, \n",
      "训练集准确率 = 0.6329365079365079, 测试集准确率 = 0.584\n",
      "#14000, 损失 = 0.652439, \n",
      "训练集准确率 = 0.6319444444444444, 测试集准确率 = 0.58\n",
      "#14500, 损失 = 0.652133, \n",
      "训练集准确率 = 0.6309523809523809, 测试集准确率 = 0.576\n",
      "#15000, 损失 = 0.651848, \n",
      "训练集准确率 = 0.623015873015873, 测试集准确率 = 0.576\n",
      "#15500, 损失 = 0.651581, \n",
      "训练集准确率 = 0.621031746031746, 测试集准确率 = 0.584\n",
      "#16000, 损失 = 0.651331, \n",
      "训练集准确率 = 0.621031746031746, 测试集准确率 = 0.596\n",
      "#16500, 损失 = 0.651096, \n",
      "训练集准确率 = 0.621031746031746, 测试集准确率 = 0.612\n",
      "#17000, 损失 = 0.650875, \n",
      "训练集准确率 = 0.6220238095238095, 测试集准确率 = 0.612\n",
      "#17500, 损失 = 0.650665, \n",
      "训练集准确率 = 0.623015873015873, 测试集准确率 = 0.604\n",
      "#18000, 损失 = 0.650468, \n",
      "训练集准确率 = 0.6240079365079365, 测试集准确率 = 0.616\n",
      "#18500, 损失 = 0.650281, \n",
      "训练集准确率 = 0.625, 测试集准确率 = 0.628\n",
      "#19000, 损失 = 0.650107, \n",
      "训练集准确率 = 0.625, 测试集准确率 = 0.628\n",
      "#19500, 损失 = 0.649944, \n",
      "训练集准确率 = 0.6240079365079365, 测试集准确率 = 0.632\n",
      "#20000, 损失 = 0.649792, \n",
      "训练集准确率 = 0.6220238095238095, 测试集准确率 = 0.628\n"
     ]
    }
   ],
   "source": [
    "fc = torch.nn.Linear(n_features, 1)\n",
    "weights, bias = fc.parameters()\n",
    "criterion = torch.nn.BCEWithLogitsLoss()\n",
    "optimizer = torch.optim.Adam(fc.parameters())\n",
    "\n",
    "x = torch.tensor(df_feature.values, dtype=torch.float32)\n",
    "y = torch.tensor(s_label.values.reshape(-1, 1), dtype=torch.float32)\n",
    "\n",
    "n_step = 20001\n",
    "for step in range(n_step):\n",
    "    if step:\n",
    "        optimizer.zero_grad()\n",
    "        loss.backward()\n",
    "        optimizer.step()\n",
    "    pred = fc(x)\n",
    "    loss = criterion(pred[train_start:train_end], y[train_start:train_end])\n",
    "    \n",
    "    if step % 500 == 0:\n",
    "        print('#{}, 损失 = {:g}'.format(step, loss))\n",
    "        \n",
    "        output = (pred > 0)\n",
    "        correct = (output == y.bool())\n",
    "        n_correct_train = correct[train_start:train_end].sum().item()\n",
    "        n_correct_test = correct[test_start:test_end].sum().item()\n",
    "        accuracy_train = n_correct_train / n_total_train\n",
    "        accuracy_test = n_correct_test / n_total_test\n",
    "        print('训练集准确率 = {}, 测试集准确率 = {}'.format(accuracy_train, accuracy_test))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
